<?php
namespace app\home\model\store;

use basic\BaseModel;
use traits\ModelTrait;

/**
 * 设备分类模型
 * Class DeviceCategory
 * @package app\home\model\store
 */
class DeviceCategory extends BaseModel
{
    use ModelTrait;

    /**
     * 主键的ID
     * @var string
     */
    protected $pk = "id";

    /**
     * 模型名称
     * @var string
     */
    protected $name = "device_category";

    /**
     * 获取商户中的所有的分类
     */
    public static function getList()
    {
        return self::where("wxapp_id", self::$wxapp_id)->where("is_del", 0)->select();
    }

    /**
     * 获取分页
     * @param array $where
     */
    public static function systemPage(array $where)
    {
        $model = new self;
        if ($where['cat_name'] != '') $model = $model->where('cat_name', "like","%$where[cat_name]%");
        $model = $model->where("is_del", 0);
        $model = $model->where("wxapp_id", self::$wxapp_id);
        $model = $model->order("sort asc,id DESC");
        return self::page($model, $where);
    }

    /**
     * 设置器
     * @param $value
     * @return int
     */
    public function setAddTimeAttr($value)
    {
        return time();
    }

    /**
     * 获取器
     * @param $value
     * @return false|string
     */
    public function getAddTimeAttr($value)
    {
        return date("Y-m-d H:i:s", $value);
    }
}